/*
 *	Copyright (C) 2008 - Mauricio Bieze Stefani
 *	This file is part of the Insano Game Engine.
 *
 *	Insano is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	Insano is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with Insano.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef ENTIDADE_H_INCLUDED
#define ENTIDADE_H_INCLUDED

#include <irrlicht.h>
#include "Animation.h"

class Entity
{
	public:
		static irr::scene::ISceneManager *smgr;

		Entity() : mesh(NULL), node(NULL), texture(NULL)
			{}
		Entity(const Entity& other);
		virtual ~Entity();

		Entity& operator=(Entity& ent);
		inline Entity* Clone()
			{ return new Entity(*this); }

		inline void setAction(Animation::Actions new_action)
			{
				if(new_action!=action)
					animation->setAction(node, (action=new_action));
			}
		inline void resetAction(Animation::Actions new_action)
			{ animation->setAction(node, (action=new_action)); }
		inline Animation::Actions getAction()
			{ return action; }

		inline void setMesh(irr::scene::IAnimatedMesh *m)
			{ mesh = m; }
		inline irr::scene::IAnimatedMesh * getMesh()
			{ return mesh; }

		inline void setNode(irr::scene::IAnimatedMeshSceneNode *n)
			{ node = n; }
		inline irr::scene::IAnimatedMeshSceneNode * getNode()
			{ return node; }

		inline void setScale(const irr::core::vector3df& s)
			{ node->setScale(s); }
		inline irr::core::vector3df getScale() const
			{ return node->getScale(); }

		inline void setRotation(const irr::core::vector3df& r)
			{ node->setRotation(r); }
		inline irr::core::vector3df getRotation() const
			{ return node->getRotation(); }

		void setPosition(const irr::core::vector3df& p)
			{ node->setPosition(p); }
		irr::core::vector3df getPosition() const
			{ return node->getPosition(); }

		inline void setTexture(irr::video::ITexture *t)
			{
				texture=t;
				node->setMaterialTexture(0, t);
				//node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
			}
		inline irr::video::ITexture* getTexture()
			{ return texture; }

		inline void setID(int id)
			{ node->setID(id); }
		inline int getID()
			{ return node->getID(); }

		inline const irr::core::aabbox3df& getBoundingBox()
			{ return node->getBoundingBox(); }

		inline void setCollisionTranslate(const irr::core::vector3df& trans)
			{ collisionTranslate = trans; }
		inline const irr::core::vector3df& getCollisionTranslate()
			{ return collisionTranslate; }

		inline void setCameraTranslate(const irr::core::vector3df& trans)
			{ cameraTranslate = trans; }
		inline const irr::core::vector3df& getCameraTranslate()
			{ return cameraTranslate; }

		inline void showDebug(bool show)
			{ node->setDebugDataVisible( show ? irr::scene::EDS_FULL : irr::scene::EDS_OFF ); }

		void setAnimation(Animation *anim)
			{ animation = anim; }
	private:
		irr::scene::IAnimatedMesh *mesh;
		irr::scene::IAnimatedMeshSceneNode *node;
		irr::video::ITexture *texture;
		irr::core::vector3df collisionTranslate;
		irr::core::vector3df cameraTranslate;
		Animation *animation;
		Animation::Actions action;
};

class Creature : public Entity
{
	public:
		Creature() {}
		Creature(const Creature& other);
		virtual ~Creature() {}

		Creature& operator=(Creature& cre);
		Creature* Clone() { return new Creature(*this); }

		unsigned short level;
		unsigned short life;
		unsigned short life_max;
		unsigned short mana;
		unsigned short mana_max;
		unsigned short stamina;
		unsigned short stamina_max;
};

class PlayerChar : public Creature
{
	public:
		PlayerChar() {}
		PlayerChar(const PlayerChar& other);
		virtual ~PlayerChar() {}

		PlayerChar& operator=(PlayerChar& pc);
		PlayerChar* Clone() { return new PlayerChar(*this); }

		unsigned short strenght;
		unsigned short agility;
		unsigned short vitality;
		unsigned short inteligence;
		unsigned short magic;
		unsigned long gold;
};

class NonPlayerChar : public Creature
{
	public:
};

class Monster : public Creature
{
	public:
};

class Item : public Entity
{
	public:
		unsigned short durability;
		unsigned short durability_max;
};

#endif // ENTIDADE_H_INCLUDED
